package com.atguigu.servlet;

import com.atguigu.bean.Book;
import com.atguigu.bean.Page;
import com.atguigu.service.BookService;
import com.atguigu.service.impl.BookServiceImpl;
import com.atguigu.utils.WebUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class BookClientServlet extends BaseServlet {
    private BookService bookService = new BookServiceImpl();


    protected void getPage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取请求参数
        String pageNoStr = request.getParameter("pageNo");
        //创建page对象
        Page<Book> pageInfo = new Page<>();
        pageInfo.setPageNostr(pageNoStr);
        //通过工具类WebUtils动态获取请求路径
        String path = WebUtils.getPath(request);
        pageInfo.setPath(path);


        //调用service处理业务逻辑，即完善page对象的过程
        Page<Book> page = bookService.getPage(pageInfo);
        //将page对象在request请求域中进行共享
        request.setAttribute("page",page);
        //转发到book_client.jsp
        request.getRequestDispatcher("/pages/client/book_client.jsp").forward(request, response);

    }


}
